package cn.easybuy.servlet.users;

import cn.easybuy.entity.PageInfo;
import cn.easybuy.entity.User;
import cn.easybuy.service.UserService;
import cn.easybuy.service.impl.UserServiceImpl;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/userPageServlet")
public class UserPageServlet extends HttpServlet {
    private UserService userService = new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            resp.setContentType("text/html;charset=utf-8");
            int pageNo = Integer.parseInt(req.getParameter("pageNo"));
            PageInfo<User> page = new PageInfo<>(pageNo,10);
            page=userService.listPage(page);
            req.setAttribute("page",page);
            RequestDispatcher dispatcher=req.getRequestDispatcher("backend/user/userList.jsp");
            dispatcher.forward(req,resp);
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
